/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dusin.weijiwufang.service.impl;

import java.sql.Timestamp;
import java.util.List;
import org.dusin.weijiwufang.bo.VisitorBean;
import org.dusin.weijiwufang.dao.VisitorDao;
import org.dusin.weijiwufang.service.VisitorService;

/**
 *
 * @author dusin
 */
public class VisitorServiceImpl implements VisitorService {

    private VisitorDao visitorDao;

    public VisitorServiceImpl(VisitorDao visitorDao) {
        this.visitorDao = visitorDao;
    }

    public VisitorBean login(String loginName, String password) {
        VisitorBean visitor = null;
        List<VisitorBean> list = visitorDao.findByLoginNamePassword(loginName, password);
        if (list.size() > 0) {
            visitor = list.get(0);
        }
        return visitor;
    }

    public void setVisitorDao(VisitorDao visitorDao) {
        this.visitorDao = visitorDao;
    }

    @Override
    public List<VisitorBean> findAll() {
        return visitorDao.findAll();
    }

    @Override
    public boolean addVisitor(VisitorBean visitor) {
        Timestamp now = new Timestamp(System.currentTimeMillis());
        visitor.setCreateTime(now);
        return visitorDao.doCreate(visitor);
    }

    @Override
    public boolean updateVisitor(VisitorBean visitor) {
        return visitorDao.doUpdate(visitor);
    }

    @Override
    public boolean deleteVisitor(long id) {
        return visitorDao.doDeleteById(id);
    }
}
